﻿#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
// 常用查找算法  count_if

class Person
{
public:
	Person(string name,int age)
	{
		this->m_Age = age;
		this->m_Name = name;
	}
	string m_Name;
	int m_Age;

};
class Greater20
{
public:
	bool operator()(int val)
	{
		return val > 20;
	}
};
class Greater20Year
{
public:
	bool operator()(Person& p)
	{
		return p.m_Age > 20;
	}
};
//1.内置数据类型
void test01()
{
	vector<int>v;
	v.push_back(10);
	v.push_back(40);
	v.push_back(30);
	v.push_back(20);
	v.push_back(40);
	v.push_back(20);
	int num = count_if(v.begin(), v.end(), Greater20()); 
	cout << num << endl;
}
//2.自定义数据类型
void test02()
{
	vector<Person>v1;
	Person p1("张三", 20);
	Person p2("张飞", 25);
	Person p3("赵云", 45);
	Person p4("刘备", 35);
	Person p5("关于", 35);
	v1.push_back(p1);
	v1.push_back(p2);
	v1.push_back(p4);
	v1.push_back(p3);
	v1.push_back(p5);
	cout << count_if(v1.begin(), v1.end(), Greater20Year());
}
int main()
{
	test01();
	test02();
}